<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>tab1</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style-type: none;
        }

        .box {
            width: 400px;
            height: 300px;
            border: 1px solid #ccc;
            margin: 100px auto;
            overflow: hidden;
        }

        .hd {
            height: 45px;
        }

        .hd span {
            display: inline-block;
            width: 90px;
            background-color: pink;
            line-height: 45px;
            text-align: center;
            cursor: pointer;
        }

        .hd span.current {
            background-color: purple;
        }

        .bd div {
            height: 255px;
            background-color: purple;
            display: none;
        }

        .bd div.current {
            display: block;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="hd" id="hd">
        <span class="current">体育</span>
        <span>娱乐</span>
        <span>新闻</span>
        <span>综合</span>
    </div>
    <div class="bd" id="bd">
        <div class="current">我是体育模块</div>
        <div>我是娱乐模块</div>
        <div>我是新闻模块</div>
        <div>我是综合模块</div>
    </div>
</div>
<script>
    //获取span 和div
    var hd = document.getElementById("hd");
    var spans = hd.getElementsByTagName("span");//伪数组  需要遍历
    var bd = document.getElementById("bd");
    var divs = bd.getElementsByTagName("div");//伪数组 需要遍历
    for (i = 0; i < spans.length; i++) {
        var span = spans[i];//拿到每一个span  冰棍儿 然后给每一个span注册绑定事件
        span.index = i;
        span.onmouseover = function () {
            //for循环排他，干掉所有span和div样式(class="";)
            for (var i = 0; i<spans.length; i++) {
                var span = spans[i];
                var div = divs[i];
                span.className = "";
                div.className = "";
            }
            //干完别人 留下自己
            this.className = "current";
            //获取当前对象index的值
            var index = this.index;
            divs[index].className = "current";
        }
    }

</script>
</body>
</html>